﻿using Lanbt.Core.Entity.EntityDB;
using Lanbt.Core.Entity.EntityDB.QuartzTable;
using Lanbt.Core.Repository.SqlService.IRepository;
using SqlSugar;

namespace Lanbt.Core.Repository.SqlService
{
    public class DatabaseRepository: IDatabaseRepository
    {
        public ISqlSugarClient _db { get; set; }

        public DatabaseRepository(ISqlSugarClient db)
        {
            _db = db;
        }

        public Task<bool> CreateDatabase()
        {
            return Task.FromResult(_db.DbMaintenance.CreateDatabase());
        }

        public Task<bool> CreateTables()
        {
            List<Type> types = new List<Type>
            {
                typeof(lanbt_user),//用户
                typeof(lanbt_role),//角色
                typeof(lanbt_power),//权限
                typeof(lanbt_system_log),//系统日志
                typeof(lanbt_system_config),//系统配置
                typeof(lanbt_user_config),//用户设置

                //quartz
                typeof(LANBT_TRIGGERS),
                typeof(LANBT_SIMPROP_TRIGGERS),
                typeof(LANBT_SIMPLE_TRIGGERS),
                typeof(LANBT_SCHEDULER_STATE),
                typeof(LANBT_PAUSED_TRIGGER_GRPS),
                typeof(LANBT_LOCKS),
                typeof(LANBT_JOB_DETAILS),
                typeof(LANBT_FIRED_TRIGGERS),
                typeof(LANBT_CRON_TRIGGERS),
                typeof(LANBT_CALENDARS),
                typeof(LANBT_BLOB_TRIGGERS),
            };

            _db.CodeFirst.InitTables(types.ToArray());

            return Task.FromResult(true);
        }
    }
}
